package struts2.action;

import java.util.ArrayList;

import DAO.Dao_addService;
import DAO.ServiceReferenceDAO;
import Entity.Checkbox;
import Entity.Reference;
import Entity.ReferenceData;

import com.opensymphony.xwork2.ActionSupport;

public class AddService extends ActionSupport{
	private ArrayList<ReferenceData> listAttend;
	private ArrayList<ReferenceData> listServiceType;
	private ArrayList<ReferenceData> listMethod;
	
	/*tuan*/
	private int serviceid;
	ArrayList<Checkbox> listCheck;
	ArrayList<Reference> listR;
	
	public ArrayList<ReferenceData> getListAttend() {
		return listAttend;
	}
	public void setListAttend(ArrayList<ReferenceData> listAttend) {
		this.listAttend = listAttend;
	}
	public ArrayList<ReferenceData> getListServiceType() {
		return listServiceType;
	}
	public void setListServiceType(ArrayList<ReferenceData> listServiceType) {
		this.listServiceType = listServiceType;
	}
	public ArrayList<ReferenceData> getListMethod() {
		return listMethod;
	}
	public void setListMethod(ArrayList<ReferenceData> listMethod) {
		this.listMethod = listMethod;
	}
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		Dao_addService dao = new Dao_addService();
		
		listAttend = dao.getList("sv_att");
		listServiceType = dao.getList("sv_type");
		listMethod = dao.getList("sv_method");
//		System.out.println("size 1 :"+listAttend.size());
//		System.out.println("size 2 :"+listServiceType.size());
//		System.out.println("size 3 :"+listMethod.size());
		//tuan
		ServiceReferenceDAO srd=new ServiceReferenceDAO();
		
		String refCode[]=new String[]{"SBeC","SBaC","SDC","SPCC","CSP","CO","Contract Outcome","Contract Obligation"};
		listR=srd.getListReference(refCode);
		ArrayList<String> listRefID=null;
		if(serviceid>0){
			listRefID=srd.getServiceReference(serviceid);
			if(listRefID==null) System.out.println("list ref id=null");
		}
		
		listCheck=new ArrayList<Checkbox>();
		Checkbox cb=null;
		
		for(Reference i:listR){
			cb=new Checkbox(i, false) ;	
			listCheck.add(cb); 
		}
		if(listRefID!=null){
			for(int i=0;i<listR.size();i++){
				for(String j:listRefID){
					//System.out.println("list R refID="+listR.get(i).getRefID());
					//System.out.println("listRefID="+j);
					if(listR.get(i).getRefID().equals(j)){
						System.out.println(j+" equal");
						listCheck.get(i).setChecked(true);
						System.out.println("check: "+listCheck.get(i).isChecked());
					}
				}
			}
		}
		
		
		return SUCCESS;
	}
	public int getServiceid() {
		return serviceid;
	}
	public void setServiceid(int serviceid) {
		this.serviceid = serviceid;
	}
	public ArrayList<Checkbox> getListCheck() {
		return listCheck;
	}
	public void setListCheck(ArrayList<Checkbox> listCheck) {
		this.listCheck = listCheck;
	}
	public ArrayList<Reference> getListR() {
		return listR;
	}
	public void setListR(ArrayList<Reference> listR) {
		this.listR = listR;
	}
	
}
